Task Class
The Task class represents a single task with full execution details and event streaming capabilities. It provides methods for monitoring task progress, streaming events, and managing task lifecycle.Properties
id
agent_id
status
input
result
events_streaming
created_at
updated_at
output_format
output_schema
Class Methods
aload(task_id, configuration=None)
Asynchronously load a task by its ID.
task_id
(str): Unique identifier for the taskconfiguration
(Optional[Configuration]): SDK configuration
Task
object with full details.
Example:
- [
ModuleException
](/API reference/exceptions): If the task is not found or access is denied.
load(task_id, configuration=None)
Synchronously load a task by its ID.
aload()
Returns: Complete Task
object.
Example:
Instance Methods
aset_status(status)
Asynchronously change the task’s execution status.
status
(AgentExecutionStatus): New status for the task
set_status(status)
Synchronously change the task’s execution status.
aset_status()
Example:
asave()
Asynchronously save task changes back to the xpander platform.
Task
object with server-side changes.
Example:
- [
ModuleException
](/API reference/exceptions): If the save operation fails.
save()
Synchronously save task changes.
Task
object.
Example:
astop()
Asynchronously stop the task execution.
Task
object with updated status.
Example:
- [
ModuleException
](/API reference/exceptions): If the task cannot be stopped.
stop()
Synchronously stop the task execution.
Task
object.
Example:
aevents()
Asynchronously stream task events in real-time.
TaskUpdateEvent
objects.
Example:
events_streaming=True
when creating the task.
events()
Synchronously stream task events.
TaskUpdateEvent
objects.
Example:
Usage Examples
Complete Task Lifecycle Management
Task Status Management
Error Handling with Tasks
Batch Task Monitoring
Related Classes
- [
Agent
](/API reference/agents/API reference/agent): Agent that creates and manages tasks
Related Types
- [AgentExecutionStatus](/API reference/types#agentexecutionstatus): Task execution statuses
- [TaskUpdateEvent](/API reference/types#taskupdateevent): Event data structure
- [TaskUpdateEventType](/API reference/types#taskupdateeventtype): Event type enumeration
- [AgentExecutionInput](/API reference/types#agentexecutioninput): Task input configuration
Related Modules
- [Agents Module](/API reference/agents): Create and manage agents
- [Events Module](/API reference/events): Event-driven programming
- [Tools Repository](/API reference/tools): Tool integration and management